<?php
/**
 * @copyright meila.com
 * @author shaopu@
 * @name 检测昵称是否可用
 * @param 
 *         $nick = 作用
 * 
 * 
 */
include('../../__global.php');

class aj_editShipping extends ml_controller 
{
    private $param;

    function initParam()
    {
        /**
         * @todo get post
         */
        $this->param['truename'] = $this->input('truename' , 'post');
        $this->param['address'] = $this->input('address' , 'post');
        $this->param['mobile'] = $this->input('mobile' , 'post');
        $this->param['zip_code'] = $this->input('zip_code' , 'post');
        $this->param['qq'] = $this->input('qq' , 'post');
        $this->param['msn'] = $this->input('msn' , 'post');
    }
    /**
     * @develop_template
     * 检查参数合法性
     */
    function checkParam()
    {
        $this->check_referer();
        if($this->param['mobile'] 
            && (!ctype_digit($this->param['mobile'])|| strlen($this->param['mobile']) != 11))
        {
            $this->api_output(ML_RCODE_PARAM);
        }
        if($this->param['qq'] && !ctype_digit($this->param['qq']))
            $this->api_output(ML_RCODE_PARAM);
        if($this->param['msn'] && filter_var($this->param['msn'] , FILTER_VALIDATE_EMAIL) === false)
            $this->api_output(ML_RCODE_PARAM);
            
        //检查权限
        if(!$this->check_permission(ML_PERMISSION_LOGIN_ONLY)) {
            $this->api_output(ML_RCODE_NOLOGIN);
        }
        else if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
            $this->api_output(ML_RCODE_NOACTIVE);
        }
    }
    /**
     * @develop_template
     * 核心业务逻辑
     */
    function main()
    {
        $oExt = new ml_model_dbUserExtInfo();
        
        $uid = $this->__visitor['uid'];
        
        if($oExt->updateShipping($uid , $this->param))
        {
            $this->api_output(ML_RCODE_SUCC);
        }
        else 
        {
            $this->api_output(ML_RCODE_BUSY , '' , ML_RMESSAGE_BUSY);
        }
    }
}

new aj_editShipping();
